public class Liczba {
	private int n;
	private static String[] litery = {"A","B","C","D","E","F"};
	public Liczba(int newy) throws Exception
	{
		if(newy<0)
			throw new Exception();
		this.n = newy;
	}
	public String zapis(int pod) throws Exception
	{
		if(pod < 2 || pod > 16) throw new Exception();
		if(n == 0) return "0";
     //HAHA
		String wyn = "";
		int temp = n;
		Integer k;
		while(temp > 0)
		{
			k = temp%pod;
			
			if(k>=10)
				wyn =  litery[k-10] + wyn;
			else
				wyn =  k.toString() + wyn;
			temp/=pod;
		}
		return wyn;
	}
}